#include "findstudywidget.h"
#include "ui_findstudywidget.h"

FindStudyWidget::FindStudyWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FindStudyWidget)
{
    ui->setupUi(this);
    on_todayBtn_clicked();
    connect(ui->searchBtn, SIGNAL(clicked(bool)), this, SIGNAL(findStudy()));
}

FindStudyWidget::~FindStudyWidget()
{
    delete ui;
}

QDateTime FindStudyWidget::getFromTime() const
{
    return ui->fromCheckBox->isChecked()?ui->fromDateTimeEdit->dateTime():QDateTime();
}

QDateTime FindStudyWidget::getToTime() const
{
    return ui->toCheckBox->isChecked()?ui->toDateTimeEdit->dateTime():QDateTime();
}

QString FindStudyWidget::getPatientId() const
{
    return ui->patientIDEdit->text();
}

QString FindStudyWidget::getPatientName() const
{
    return ui->patientNameEdit->text();
}

QString FindStudyWidget::getAccNum() const
{
    return ui->accNumberEdit->text();
}

QString FindStudyWidget::getModality() const
{
    return ui->modalityCombo->currentText();
}

void FindStudyWidget::on_todayBtn_clicked()
{
    ui->fromCheckBox->setChecked(true);
    ui->fromDateTimeEdit->setDate(QDate::currentDate());
    ui->fromDateTimeEdit->setTime(QTime(0, 0));

    ui->toCheckBox->setChecked(true);
    ui->toDateTimeEdit->setDate(QDate::currentDate());
    ui->toDateTimeEdit->setTime(QTime(23, 59, 59, 999));

}

void FindStudyWidget::on_yesterdayBtn_clicked()
{
    ui->fromCheckBox->setChecked(true);
    ui->fromDateTimeEdit->setDate(QDate::currentDate().addDays(-1));
    ui->fromDateTimeEdit->setTime(QTime(0, 0));

    ui->toCheckBox->setChecked(true);
    ui->toDateTimeEdit->setDate(QDate::currentDate().addDays(-1));
    ui->toDateTimeEdit->setTime(QTime(23, 59, 59, 999));

}

void FindStudyWidget::on_latestWeekBtn_clicked()
{
    ui->fromCheckBox->setChecked(true);
    ui->fromDateTimeEdit->setDate(QDate::currentDate().addDays(-6));
    ui->fromDateTimeEdit->setTime(QTime(0, 0));

    ui->toCheckBox->setChecked(true);
    ui->toDateTimeEdit->setDate(QDate::currentDate());
    ui->toDateTimeEdit->setTime(QTime(23, 59, 59, 999));

}

void FindStudyWidget::on_latestMonthBtn_clicked()
{
    ui->fromCheckBox->setChecked(true);
    ui->fromDateTimeEdit->setDate(QDate::currentDate().addDays(-30));
    ui->fromDateTimeEdit->setTime(QTime(0, 0));

    ui->toCheckBox->setChecked(true);
    ui->toDateTimeEdit->setDate(QDate::currentDate());
    ui->toDateTimeEdit->setTime(QTime(23, 59, 59, 999));

}

void FindStudyWidget::on_clearBtn_clicked()
{
    ui->fromCheckBox->setChecked(false);
    ui->toCheckBox->setChecked(false);
    ui->modalityCombo->setCurrentIndex(0);
    ui->patientIDEdit->clear();
    ui->patientNameEdit->clear();
    ui->accNumberEdit->clear();
}
